import React from 'react';
import { Form, Button } from 'antd';
import { FormPro } from '@/components';
import { FormInstance } from 'antd/lib/form';
import { FormItem } from '@/components/FormPro/types';

type Props = {
  formList: FormItem[];
  onSearch?(e: any): any;
}

class Search extends React.PureComponent<Props> {
  form = React.createRef<FormInstance>();

  private onResetForm = () => {
    this.form?.current?.resetFields?.();
    this.props?.onSearch?.({});
  }

  render() {
    const {
      onSearch,
      formList,
      children
    } = this.props;
    return (
      <FormPro
        layout="inline"
        ref={this.form}
        formList={formList}
        onSubmit={onSearch}
      >
        <Form.Item>
          <Button
            type="default"
            children="重置"
            onClick={this.onResetForm}
          />
        </Form.Item>
        <Form.Item>
          <Button
            type="primary"
            children="查询"
            htmlType="submit"
          />
        </Form.Item>
        <Form.Item>
          {children}
        </Form.Item>
      </FormPro>
    )
  }
}

export default Search;

